

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import junit.framework.Assert;

import org.junit.BeforeClass;
import org.junit.Test;

import com.landerer.dto.EmployeeDTO;
import com.landerer.service.EmployeeServiceRemoteBusiness;

public class EmployeeServiceIntegrationTest {
	
	private static Context namingContext;

	private static EmployeeServiceRemoteBusiness bean;
	
	private static final String JNDI_NAME = "java:global/EmployeeMgmt/EmployeeServiceAdaptor!com.landerer.service.EmployeeServiceRemoteBusiness";
	
	@BeforeClass
	public static void obtainProxyReferences() throws NamingException {
		namingContext = new InitialContext();
		bean = (EmployeeServiceRemoteBusiness) namingContext.lookupLink(JNDI_NAME);
	}
	
	@Test
	public void testCreationOfNewEmployee() {
		final String name = "Andreas Landerer";
		final long salary = 102000L;
		
		EmployeeDTO employee = bean.createEmployee(name, salary);
		Assert.assertNotNull(employee);
		
		employee = bean.findEmployeeById(employee.getId());
		Assert.assertNotNull(employee);
		Assert.assertEquals(name, employee.getName());
		Assert.assertEquals(salary, employee.getSalary());
	}
}
